package com.mynewspaper.app;

import java.util.ArrayList;
import java.util.List;

import com.mynewspaper.entity.User;

import er.extensions.appserver.ERXSession;

public class Session extends ERXSession {
	private static final long serialVersionUID = 1L;

	private ArrayList<User> users = new ArrayList<User>();
	private User user = null;

	public void addUser(User user) {
		users.add(user);
	}

	public List<User> getUsers() {
		return users;
	}

	public Session() {
		super();
		setStoresIDsInCookies(true);
		setStoresIDsInURLs(false);
	}

	public User getUser() {
		return this.user;
	}

	// TODO move this method to direct action layer 
	public Boolean login(String login, String password) {
		for (User user : getUsers()) {
			if (user.getUserLogin().equals(login)
					&& user.getUserPassword().equals(password)) {
				this.user = user;
				return true;
			}
		}
		return false;
	}

	public void logOut() {
		this.user = null;
	}
}
